<?php
$competition = $data['competition'];
//dump($data);
//dump($_ENV);
?>
<!DOCTYPE html>
<html lang="zhcn">
<head>
    <include file="Common/meta" />
    <title>职位详情 - {$_ENV['site'][0]['title']}</title>
    <include file="Common/link" />
</head>
<body>
<include file="Common/header" />
<div class="container container-main">
    <div class="row">
        <div class="contain-main">
            <div class="box box-main">
                <div class="box-body">
                    <ul>
                        <li>比赛名称：{$competition['title']}</li>
                        <if condition="$competition['type'] eq 0">
                            <li>举办方：<span class="label label-primary">官方组织</span></li>
                            <else />
                            <li>举办方：<a href="">XXX</a> </li>
                        </if>
                        <li>发布时间：{$competition['create_time']|strtotime|date="Y-m-d H:i",###} </li>

                    </ul>
                    <div>
                        比赛内容：{$competition['contain']}
                    </div>
                    <div>
                        <if condition="$data['is_join']">
                            <button id="signup" class="btn btn-primary" type="button" disabled>已报名</button>
                            <else />
                            <button id="signup" class="btn btn-primary" type="button">我要报名</button>
                        </if>

                    </div>


                </div>

            </div>
        </div>
        <include file="Common/sidebar" />
    </div>
</div>
<include file="Common/nav"/>
<include file="Common/script" />
<script>
    var pageConfig = {
        userType: '{$_ENV['user']['type']}',
        competitionId: '{$competition['cpt_id']}'
    };

    // 竞赛报名
    $('#signup').on('click', function () {

        // 如果未登录，跳转到登陆界面
        if (pageConfig.userType !== '1') {
            console.log(1);
            window.location.href = '/Page/login';
            return;
        }
        $.ajax({
            url: '/competition/join',
            data: {
                cpt_id: pageConfig.competitionId,
            },
            type: 'POST',
            dataType: 'json',
            success: function (obj) {
                if (obj.code === 0) {
                    eui.alert('报名成功', function () {
                        location.reload(true);
                    });
                } else {
                    eui.alert('报名失败，' + obj.msg);
                }
            },
            error: function () {
                eui.alert('系统出错');
            }
        })
    });

</script>
</body>
</html>

